<style lang="less">

</style>

<template>
  <div >
    <el-form :model="queryForm" label-width="114px" :rules="rules" ref="addform" label-suffix="：">
      <el-row :getter="10">
        <el-col :span="12">
          <el-form-item :label="$t('graduate.semester')" prop="calendarYear">
            <!-- <CalendarSelect v-if="dataProp==='编辑'"  :disabled="dataProp!=='新增'&&dataProp!=='编辑'" v-model="queryForm.calendarYear" @change="changeSelect" @load-done="loadDone"></CalendarSelect> -->
            <CalendarSelect :defaulted='dataProp==="新增"?false:true' :disabled="dataProp!=='新增'&&dataProp!=='编辑'" v-model="queryForm.calendarYear" @input='changeInput' @change="changeSelect" @load-done="loadDone"></CalendarSelect>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('graduate.trainingLevel')">
            <DictSelect v-if="dataProp=='新增'||dataProp=='编辑'"
              :filterable='false'
              :plzSelect="$t('internship.pleaseSelect')"
              
              v-model="queryForm.TrainingLevelList"
              @change="changeTrain"
              :data="options.TrainingLevel"
              multiple style="width: 100%">
              <!-- :disabled="dataProp!=='新增'&&dataProp!=='编辑'" -->
            </DictSelect>
            <el-input v-if="dataProp=='详情'"
              type="textarea" disabled
             :rows="1"
              v-model="queryForm.TrainingLevelList">
            </el-input>
            <!-- @change='pleaseSelect' -->
            <!-- <el-select multiple collapse-tags :disabled="dataProp!=='新增'&&dataProp!=='编辑'" v-model="queryForm.TrainingLevelList" clearable style="width: 100%">
                <el-option
                  v-for="item in options.TrainingLevel"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
            </el-select> -->
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :getter="10">
        <el-col :span="12">
          <el-form-item :label="$t('graduate.trainingClasse')">
            <!-- labelAll="请选择" -->
            <DictSelect v-if="dataProp=='新增'||dataProp=='编辑'"
              clearable :filterable='false'
              :plzSelect="$t('internship.pleaseSelect')"
              @change="changeCategory"
             
              v-model="queryForm.trainingCategory"
              :data="options.trainingCategory"
              multiple style="width: 100%">
            </DictSelect>
            <el-input v-if="dataProp=='详情'"
              type="textarea" disabled
              :rows="1"
              v-model="queryForm.trainingCategory">
            </el-input>
             <!-- :disabled="dataProp!=='新增'&&dataProp!=='编辑'" -->
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <!-- labelAll="请选择" -->
          <el-form-item :label="$t('graduate.learnType')">
             <el-select disabled v-model="queryForm.degreeType"  style="width: 100%">
              <el-option  label="专业型" value="2"> </el-option>
            </el-select>
            <!-- <DictSelect clearable style="width: 100%"
              v-model="queryForm.degreeTypeList" :filterable='false'
              @change="changeTypeList"
              :plzSelect="$t('internship.pleaseSelect')"
              :data="options.degreeType" disabled>
            </DictSelect> -->
            
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :getter="10">
        <el-col :span="12">
          <el-form-item :label="$t('graduate.formsLearn')">
            <DictSelect clearable style="width: 100%" v-if="dataProp=='新增'||dataProp=='编辑'"
              v-model="queryForm.learnFormList" 
              multiple @change="changeformLear"
              :plzSelect="$t('internship.pleaseSelect')"
              :data="options.formLearning" >
              <!-- :disabled="dataProp!=='新增'&&dataProp!=='编辑'" -->
            </DictSelect>
            <el-input v-if="dataProp=='详情'"
              type="textarea" disabled
              :rows="1"
              v-model="queryForm.learnFormList">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('graduate.college')">
            <DictSelect clearable style="width: 100%" v-if="dataProp=='新增'||dataProp=='编辑'"
              v-model="queryForm.collegeAcademyList" 
              multiple filterable
              @change="collegeChange"
              :plzSelect="$t('internship.pleaseSelect')"
              :data="options.faculty" >
              <!-- :disabled="dataProp!=='新增'&&dataProp!=='编辑'" -->
            </DictSelect>
            <el-input v-if="dataProp=='详情'"
              type="textarea" disabled
              :rows="1"
              v-model="queryForm.collegeAcademyList">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :getter="10">
        <el-col :span="12">
          <el-form-item :label="$t('graduate.major')">
           
            <el-select collapse-tags @change="changeMajor" v-if="dataProp=='新增'||dataProp=='编辑'"   v-model="queryForm.majorList" multiple filterable clearable  style="width: 100%">
              <el-option 
                  v-for="item in options.profession"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code">
              </el-option>
            </el-select>
            <!-- :disabled="dataProp!=='新增'&&dataProp!=='编辑'" -->
            <el-input v-if="dataProp=='详情'"
              type="textarea" disabled
              :rows="1"
              v-model="queryForm.majorList">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('graduate.startTime')" size="small" prop="signStart">
            <el-date-picker
              :placeholder="$t('internship.pleaseSelect')"
              style="width: 100%"
              :clearable="false"
              :disabled="dataProp!=='新增'&&dataProp!=='编辑'"
              v-model="queryForm.signStart"
              :picker-options="pickerOptionsStart"
              type="date"
              value-format="yyyy-MM-dd"
              format="yyyy-MM-dd">
            </el-date-picker>
            <!-- value-format="yyyy-MM-dd HH:mm:ss" -->
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :getter="10">
        <el-col :span="12">
          <el-form-item :label="$t('graduate.endTime')" size="small" prop="signEnd">
            <el-date-picker
              style="width: 100%"
              :placeholder="$t('internship.pleaseSelect')"
              :disabled="dataProp!=='新增'&&dataProp!=='编辑'"
              :clearable="false"
              v-model="queryForm.signEnd"
              :picker-options="pickerOptionsEnd"
              type="date"
              value-format="yyyy-MM-dd"
              format="yyyy-MM-dd">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('graduate.progressFrequency')" label-width="141px"  prop="submitFrequency">
            <el-input :disabled="dataProp!=='新增'&&dataProp!=='编辑'" :placeholder="$t('internship.pleaseEnter')" v-model="queryForm.submitFrequency" maxlength="32"></el-input>
            
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :getter="10">
        <el-col :span="12">
          <el-form-item :label="$t('graduate.curriculum')" prop="">
            <el-button :disabled="dataProp!=='新增'&&dataProp!=='编辑'" @click="graduateAdd">{{$t('graduate.add')}}</el-button>
            
            <!-- <el-input :disabled="dataProp!=='新增'&&dataProp!=='编辑'"  :placeholder="$t('internship.pleaseEnter')" v-model="queryForm.courseCode" maxlength="64"></el-input> -->
          <!-- <el-autocomplete class="inline-input" style="width: 100%" :disabled="dataProp!=='新增'&&dataProp!=='编辑'"
              v-model="queryForm.courseCode" :fetch-suggestions="querySearch" :trigger-on-focus="false"
              @select="handleSelect" @input="handleChange">
            </el-autocomplete> -->
          </el-form-item>
        </el-col>
       <el-col>
         <el-form :model="assessIndexDetailTable" ref="assessIndexDetailTable" :rules="rulesForm">
            <edu-table :pagination="false" :order='false' :selection='false' stripe :data="assessIndexDetailTable.internshipData" size="mini">
              <edu-table-column :label="$t('internProgress.grade')" prop="grade">
                <template slot-scope="scope">
                  <el-form-item  style="margin-top: 15px;" :prop="'internshipData.' + scope.$index + '.grade'" label-width="0" :rules="rulesForm.grade">
                    <!-- <el-input :disabled="dataProp!=='新增'&&dataProp!=='编辑'" v-model.trim="scope.row.grade" ></el-input> -->
                    <el-date-picker
                      v-model="scope.row.grade"
                      type="year"
                      :disabled="dataProp!=='新增'&&dataProp!=='编辑'"
                      format="yyyy"
                      value-format="yyyy" >
                    </el-date-picker>
                    <!-- <el-date-picker
                      v-model="scope.row.grade"
                      type="year"
                      placeholder="选择年">
                    </el-date-picker>
                    {{ scope.row.grade }} -->
                  </el-form-item>
                </template>
              </edu-table-column>
              <edu-table-column :label="$t('graduate.curriculum')" prop="courseCode">
                <template slot-scope="scope">
                  <el-form-item  style="margin-top: 15px;" :prop="'internshipData.' + scope.$index + '.courseCode'" label-width="0" :rules="rulesForm.courseCode">
                    <el-input :disabled="dataProp!=='新增'&&dataProp!=='编辑'" v-model.trim="scope.row.courseCode" maxlength="32"></el-input>
                  </el-form-item>
                </template>
              </edu-table-column>
              <edu-table-column :label="$t('graduate.operate')">
                <template slot-scope="scope">
                  <el-button type="text" :disabled="dataProp!=='新增'&&dataProp!=='编辑'" @click="removeOutline(scope.$index)" >{{$t('requirement.remove')}}</el-button>
                </template>
              </edu-table-column>
            </edu-table>
          </el-form>
       </el-col>
      </el-row>
    </el-form>
    <el-dialog
      width="25%"
      ref="innerDialog"
      :title="$t('graduateBase.prompt')"
      :visible.sync="innerVisible"
      append-to-body
      :top="'28vh'">
      <div style="text-align: left;margin-bottom: 25px;">{{$t('graduateBase.cancelTip')}}</div>
      <div style="text-align: right;">
        <el-button type="primary" @click="confirmInner">{{$t('common.btn.confirm')}}</el-button>
        <el-button @click="cancelInner">{{$t('common.btn.cancel')}}</el-button>
        <el-button type="primary" @click="confirmAndClose">{{$t('graduateBase.saveAndClose')}}</el-button>
      </div>
    </el-dialog>
    <el-row type="flex" class="row-bg" justify="end">
      <el-button @click="cancelDialog">{{$t('graduate.cancel')}}</el-button>
      <el-button v-if="dataProp!=='详情'" type="danger" @click="affirmForm">{{$t('graduate.define')}}</el-button>
    </el-row>

  </div>
</template>

<script>
import { queryDic } from "common/src/api/dictionary";
import UTILS from "common/src/utils/utils";
import graduateStudent from 'common/src/api/graduateStudent/graduateStudent';
export default {
  
  props: {
    
    dataList: {
      type: Array
    },
    dataProp: {
      type: String
    },
    dataListProp: {
      type: Object
    },
    showFlag: {
      type: Boolean
    },
    agent: {
      type: Boolean,
      default: false,
      required: false
    },
    admin: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    let validateNum = (rule, value, callback) => {
      let reg = /^[1-9]*$/;
      if (!reg.test(value) || value === '') {
        return callback(new Error(this.$t('mainbase.pleaseNumber')));
      }
      return callback();
    };
    let cannotContain = (rule, value, callback) => {
      let reg = /[`$]/im;
      if (reg.test(value)) {
        return callback(new Error(this.$t('identificationToDoList.cannotContain')));
      } else if (value === '') {
        return callback(new Error(this.$t('internship.pleaseEnter')));
      }
      return callback();
    };
    return {
      innerVisible: false,
      addhandle: false,
      restaurants: [],
      assessIndexDetailTable: {

        internshipData: []
      },
      // dataList: [],
      queryForm: {
        signEnd: null,
        signStart: null,
        calendarYear: '',
        calendarTerm: '',
        calendarName: '',
        submitFrequency: '',
        trainingCategory: [],
        trainingType: '', // 培养类别
        collegeAcademyList: [], 
        collegeAcademy: '', // 学院
        degreeTypeList: '2',
        degreeType: '2', // 学位类型
        learnFormList: [],
        learnForm: '', // 学习形式
        courseCode: '',
        majorList: [],
        major: '', // 专业
        TrainingLevelList: [],
        trainingLevel: ''  // 培养层次
      },
      options: {
        TrainingLevel: [],
        degreeType: [],
        formLearning: [],
        faculty: [],
        profession: [],
        trainingCategory: []
      },
      pickerOptionsStart: {
      
        disabledDate: time => {
          let endDateVal = this.queryForm.signEnd;
          if (endDateVal) {
            return time.getTime() > new Date(endDateVal).getTime();
          }
        }
      },
      pickerOptionsEnd: {
        disabledDate: time => {
          let beginDateVal = this.queryForm.signStart;
          if (beginDateVal) {
            return time.getTime() <= new Date(beginDateVal).getTime()- 86400000;
          }
        }
      },
      rulesForm: {
        grade: [
          { required: true, message: this.$t('internship.pleaseSelect'), trigger: 'change' }
        ],
        courseCode: [
          { required: true, message: this.$t('internship.pleaseEnter'), trigger: 'blur' },
          { validator: cannotContain, trigger: 'blur' }
        ]
      },
      rules: {
        courseCode: [
          { required: true, message: this.$t('internship.pleaseSelect'), trigger: 'change' }
          // { required: true, message: this.$t('internship.pleaseEnter'), trigger: 'blur' }
        ],
        calendarYear: [
          { required: true, message: this.$t('internship.pleaseSelect'), trigger: 'change' }
        ],
        collegeAcademyList: [
          { required: true, message: this.$t('internship.pleaseSelect'), trigger: 'change' }
        ],
        submitFrequency: [
          { required: true, validator: validateNum, trigger: 'blur' }
        ],
        signStart: [
          { required: true, message: this.$t('internship.pleaseSelect'), trigger: 'change' }
        ],
        signEnd: [
          { required: true, message: this.$t('internship.pleaseSelect'), trigger: 'change' }
        ]
      },
      courseCode: '',
      obj: {
        pageNum_: 0,
        pageSize_: 200,
        college: [],
        condition: ''
      }
    };
  },
  watch: {
    showFlag: {
      handler: function(newV, oldV) {
        if (newV) {
          if (this.dataProp === '编辑') {
            let list = JSON.parse(JSON.stringify(this.dataListProp));
            if (list.courseList) {
              list.courseList.forEach(el => {
                el.grade = el.grade + '';
              });
            }
            this.assessIndexDetailTable.internshipData = list.courseList;
            this.obj.condition = list.courseCode;
            this.queryForm = list;
            this.dataList.forEach(el => {
              if (el.fullName === list.calendarName) {

                this.queryForm.calendarYear = el.id;
              }
            });
            // 学院
            this.queryForm.collegeAcademyList = list.collegeAcademy ? list.collegeAcademy.split(',') : ['全部'];
            // this.queryForm.collegeAcademyList = list.collegeAcademyStr.split(',');
            if (this.queryForm.collegeAcademyList.length > 0) {
              graduateStudent.getDegreeByCollege(this.queryForm.collegeAcademyList).then(res => {
                this.options.profession = res.data;
              });
              this.queryForm.collegeAcademy = list.collegeAcademy ? list.collegeAcademy.split(',') : '';
              // this.queryForm.collegeAcademy = college.length > 0 ? college.join() : '';
            } else {
              this.queryForm.collegeAcademy = '';
            }
            // 培养类别
            this.queryForm.trainingCategory = list.trainingType ? list.trainingType.split(',') : ['全部'];
            // this.queryForm.trainingCategory = list.trainingTypeStr.split(',');
            // 学位类型
            // this.queryForm.degreeTypeList = list.degreeTypeStr.split(',');
            this.queryForm.degreeType = '2';
            // 学习形式
            this.queryForm.learnFormList = list.learnForm ? list.learnForm.split(',') : ['全部'];
            // this.queryForm.learnFormList = list.learnFormStr.split(',');
            // 专业
            this.queryForm.majorList = list.major ? list.major.split(',') : ['全部'];
            // this.queryForm.majorList = list.majorStr.split(',');
            // 培养层次
            this.queryForm.TrainingLevelList = list.trainingLevel ? list.trainingLevel.split(','): ['全部'];
            // this.queryForm.TrainingLevelList = list.trainingLevelStr.split(',');
            this.$refs['addform'].clearValidate();
          } else if (this.dataProp === '新增') {
            this.dataListProp = {};
            this.$refs['addform'].resetFields();
            this.$refs['assessIndexDetailTable'].resetFields();
            this.assessIndexDetailTable.internshipData = [];
            this.queryForm.collegeAcademyList = [];
            this.queryForm.trainingCategory = [];
            this.queryForm.degreeTypeList = [];
            this.queryForm.learnFormList = [];
            this.queryForm.majorList = [];
            this.queryForm.TrainingLevelList = [];
            this.queryForm.submitFrequency='';
            this.queryForm.courseCode='';
            this.queryForm.signEnd = null;
            this.queryForm.signStart = null;
            // this.queryForm.calendarYear = '';
          } else if (this.dataProp === '详情') {
            let list = JSON.parse(JSON.stringify(this.dataListProp));
            if (list.courseList) {
              list.courseList.forEach(el => {
                el.grade = el.grade + '';
              });
            }
            this.assessIndexDetailTable.internshipData = list.courseList;
            this.obj.condition = list.courseCode;
            this.queryForm = list;
            this.dataList.forEach(el => {
              if (el.fullName === list.calendarName) {
                this.queryForm.calendarYear = el.id;
              }
            });
            // 学院
            // this.queryForm.collegeAcademyList = list.collegeAcademy ? list.collegeAcademy.split(',') : ['全部'];
            this.queryForm.collegeAcademyList = list.collegeAcademyStr.length > 0 ? list.collegeAcademyStr.split(',') : '全部';
            // 培养类别
            // this.queryForm.trainingCategory = list.trainingType ? list.trainingType.split(',') : ['全部'];
            this.queryForm.trainingCategory = list.trainingTypeStr.length > 0 ? list.trainingTypeStr.split(',') : '全部';
            // 学位类型
            // this.queryForm.degreeTypeList = list.degreeTypeStr.split(',');
            this.queryForm.degreeType = '2';
            // 学习形式
            // this.queryForm.learnFormList = list.learnForm ? list.learnForm.split(',') : ['全部'];
            this.queryForm.learnFormList = list.learnFormStr.length > 0 ? list.learnFormStr.split(',') : '全部';
            // 专业
            // this.queryForm.majorList = list.major ? list.major.split(',') : ['全部'];
            this.queryForm.majorList = list.majorStr.length > 0 ? list.majorStr.split(',') : '全部';
            // 培养层次
            // this.queryForm.TrainingLevelList = list.trainingLevel ? list.trainingLevel.split(','): ['全部'];
            this.queryForm.TrainingLevelList = list.trainingLevelStr.length > 0 ? list.trainingLevelStr.split(',') : '全部';
          }
        }
      }
    }
  },
  mounted() {
    if (this.dataProp === '编辑') {
      let list = JSON.parse(JSON.stringify(this.dataListProp));
      if (list.courseList) {
        list.courseList.forEach(el => {
          el.grade = el.grade + '';
        });
      }
      this.assessIndexDetailTable.internshipData = list.courseList;
      this.obj.condition = list.courseCode;
      this.queryForm = list;
      this.dataList.forEach(el => {
        if (el.fullName === list.calendarName) {
          this.queryForm.calendarYear = el.id;
        }
      });
      // 学院
      this.queryForm.collegeAcademyList = list.collegeAcademy ? list.collegeAcademy.split(',') : ['全部'];
      // this.queryForm.collegeAcademyList = list.collegeAcademyStr.split(',');
      if (this.queryForm.collegeAcademyList.length > 0) {
        graduateStudent.getDegreeByCollege(this.queryForm.collegeAcademyList).then(res => {
          this.options.profession = res.data;
        });
        this.queryForm.collegeAcademy = list.collegeAcademy ? list.collegeAcademy.split(',') : '';
        // this.queryForm.collegeAcademy = college.length > 0 ? college.join() : '';
      } else {
        this.queryForm.collegeAcademy = '';
      }    
      // this.collegeChange(college);
      // this.queryForm.collegeAcademy = college.length > 0 ? college.join() : '';
      // 培养类别
      this.queryForm.trainingCategory = list.trainingType ? list.trainingType.split(',') : ['全部'];
      // this.queryForm.trainingCategory = list.trainingTypeStr.split(',');
      // 学位类型
      // this.queryForm.degreeTypeList = list.degreeTypeStr.split(',');
      this.queryForm.degreeType = '2';
      // 学习形式
      this.queryForm.learnFormList = list.learnForm ? list.learnForm.split(',') : ['全部'];
      // this.queryForm.learnFormList = list.learnFormStr.split(',');
      // 专业
      this.queryForm.majorList = list.major ? list.major.split(',') : ['全部'];
      // this.queryForm.majorList = list.majorStr.split(',');
      // 培养层次
      this.queryForm.TrainingLevelList = list.trainingLevel ? list.trainingLevel.split(','): ['全部'];
      // this.queryForm.TrainingLevelList = list.trainingLevelStr.split(',');
      // this.$refs['addform'].clearValidate();
    } else if (this.dataProp === '新增') {
      this.dataListProp = {};
      // this.$refs['addform'].resetFields();
      this.assessIndexDetailTable.internshipData = [];
      this.queryForm.collegeAcademyList = [];
      this.queryForm.trainingCategory = [];
      this.queryForm.degreeTypeList = [];
      this.queryForm.learnFormList = [];
      this.queryForm.majorList = [];
      this.queryForm.TrainingLevelList = [];
      this.queryForm.submitFrequency='';
      this.queryForm.courseCode='';
      this.queryForm.signEnd = null;
      this.queryForm.signStart = null;
      // this.queryForm.calendarYear = '';
      
    } else if (this.dataProp === '详情') {
      let list = JSON.parse(JSON.stringify(this.dataListProp));
      if (list.courseList) {
        list.courseList.forEach(el => {
          el.grade = el.grade + '';
        });
      }
      this.assessIndexDetailTable.internshipData = list.courseList;
      this.obj.condition = list.courseCode;
      this.queryForm = list;
      this.dataList.forEach(el => {
        if (el.fullName === list.calendarName) {
          this.queryForm.calendarYear = el.id;
        }
      });
      // 学院
      // this.queryForm.collegeAcademyList = list.collegeAcademy ? list.collegeAcademy.split(',') : ['全部'];
      this.queryForm.collegeAcademyList = list.collegeAcademyStr.length > 0 ? list.collegeAcademyStr.split(',') : '全部';
      // 培养类别
      // this.queryForm.trainingCategory = list.trainingType ? list.trainingType.split(',') : ['全部'];
      this.queryForm.trainingCategory = list.trainingTypeStr.length > 0 ? list.trainingTypeStr.split(',') : '全部';
      // 学位类型
      // this.queryForm.degreeTypeList = list.degreeTypeStr.split(',');
      this.queryForm.degreeType = '2';
      // 学习形式
      // this.queryForm.learnFormList = list.learnForm ? list.learnForm.split(',') : ['全部'];
      this.queryForm.learnFormList = list.learnFormStr.length > 0 ? list.learnFormStr.split(',') : '全部';
      // 专业
      // this.queryForm.majorList = list.major ? list.major.split(',') : ['全部'];
      this.queryForm.majorList = list.majorStr.length > 0 ? list.majorStr.split(',') : '全部';
      // 培养层次
      // this.queryForm.TrainingLevelList = list.trainingLevel ? list.trainingLevel.split(','): ['全部'];
      this.queryForm.TrainingLevelList = list.trainingLevelStr.length > 0 ? list.trainingLevelStr.split(',') : '全部';
    }
  },
  methods: {
    graduateAdd() {
      this.assessIndexDetailTable.internshipData.push(
        {
          grade: '', courseCode: ''
        }
      );
    },
    removeOutline(index) {
      this.assessIndexDetailTable.internshipData.splice(index, 1);
    },
    // 查询code
    handleChange(val) {
      // let obj = {
      //   pageNum_: 0,
      //   pageSize_: 100
      // };
      // obj.condition = val.target.value;
      this.obj.condition = val;
      this.postGetCourseList();
    },
    handleSelect (val) {
      this.courseCode = val.code;
    },
    postGetCourseList() {
      const params = _.omit(
				Object.assign(this.obj, {
					facultys: this.obj.college
				}),
				["college"]
			);
			if(params.facultys.length < 1){
				params.facultys = null;
      }
      graduateStudent.getCourseList(params).then(response => {
				if (response.code == 200) {
          this.restaurants = response.data.list;
					this.restaurants.map((value) => {
            value['value'] = value.name + '(' + value.code + ')';
          });
        }
      });
    },
    // 输入搜索
    querySearch(queryString, cb) {
      let restaurants = this.restaurants;
      let results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
      // 调用 callback 返回建议列表的数据
      // clearTimeout(this.timeout);
      // this.timeout = setTimeout(() => {
      //   cb(results);
      // }, 3000 * Math.random());
      cb(results);
    },
    createFilter(queryString) {
      return (restaurant) => {
        return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0 || restaurant.code.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
      };
    },
    // 课程取消
    beforeClose() {
      this.$refs.progressFrequency.cancelDialog();
    },
    // 课程取消
    changeClose() {
      this.addhandle = false;
    },
    // 专业改变
    changeMajor(val) {
      this.queryForm.majorList.forEach(el => {
        if (el === '全部') {
          delete this.queryForm.majorList[0];
        }
      });
    },
    // 学习形式改变
    changeformLear() {
      this.queryForm.learnFormList.forEach(el => {
        if (el === '全部') {
          delete this.queryForm.learnFormList[0];
        }
      });
    },
    // 培养类别改变
    changeCategory() {
      this.queryForm.trainingCategory.forEach(el => {
        if (el === '全部') {
          delete this.queryForm.trainingCategory[0];
        }
      });
    },
    // 学位类型改变
    changeTypeList() {
      this.queryForm.degreeTypeList.forEach(el => {
        if (el === '全部') {
          delete this.queryForm.degreeTypeList[0];
        }
      });
      
    },
    // 培养层次改变
    changeTrain() {
      this.queryForm.TrainingLevelList.forEach(el => {
        if (el === '全部') {
          delete this.queryForm.TrainingLevelList[0];
        }
      });
      
    },
    // 字典获取
    getOptions() {
      // 筛选条件字典查询
      let data = {
        lang: this.$store.getters.language || "cn",
        type: "allChild",
        keys: ["X_PYCC", 'X_PYLB', 'X_XWLX', 'X_XXXS', 'X_YX']
      };
      queryDic(data).then(res => {
        UTILS.fillSelect(
          {
            trainingCategory: "X_PYLB",
            degreeType: "X_XWLX",
            formLearning: "X_XXXS",
            faculty: "X_YX",
            TrainingLevel: "X_PYCC"
          },
          res.data,
          this.options
        );
      });
    },
    pleaseSelect(val) {
    },
    
    // 内层弹框确定
    confirmInner() {
      this.innerVisible = false;
      this.queryForm.calendarYear = '';
      this.options.profession = [];
      this.restaurants = [];
      this.assessIndexDetailTable.internshipData = [];
      this.$refs['addform'].clearValidate();
      this.$emit("cancel-dialog", false);
    },
    // 内层弹框取消
    cancelInner() {
      this.innerVisible = false;
    },
    // 内层弹框保存
    confirmAndClose() {
      this.affirmForm();
      this.innerVisible = false;
      // this.$emit("cancel-dialog", false);
    },
    // 取消
    cancelDialog() {
      if (this.dataProp === '详情') {
        this.$emit("cancel-dialog", false);
      } else {
        this.$refs['addform'].clearValidate();
        let isEmpty = true;
        for (let key in this.queryForm) {
          if (this.queryForm.trainingCategory.length > 0) {
            isEmpty = false;
          } else if (this.queryForm.collegeAcademyList.length > 0) {
            isEmpty = false;
          } else if (this.queryForm.learnFormList.length > 0) {
            isEmpty = false;
          } else if (this.queryForm.majorList.length > 0) {
            isEmpty = false;
          } else if (this.queryForm.TrainingLevelList.length > 0) {
            isEmpty = false;
          } else if(this.queryForm.signEnd) {
            isEmpty = false;
          } else if (this.queryForm.signStart) {
            isEmpty = false;
          } else if(this.queryForm.calendarYear) {
            isEmpty = false;
          } else if (this.queryForm.submitFrequency) {
            isEmpty = false;
          } else if(this.queryForm.courseCode) {
            isEmpty = false;
          }
        }
        
        if (isEmpty && this.assessIndexDetailTable.internshipData.length < 1) {
          this.innerVisible = false;
          this.queryForm.calendarYear = '';
          this.options.profession = [];
          this.restaurants = [];
          this.assessIndexDetailTable.internshipData = [];
          this.$emit("cancel-dialog", false);
        } else {
          this.innerVisible = true;
        }
      }
      
    },
    loadDone(data, val) {
      this.dataList = data;
    },
    changeInput(val) {
    },
    // 学期选择
    changeSelect(val) {
      this.dataList.forEach(el => {
        if (val === el.id) {
          this.queryForm.calendarYear = el.year;
          this.queryForm.calendarTerm = el.term;
          this.queryForm.calendarName = el.fullName;
        }
      });
    },
    changeInput(val) {
    },
    // 学院选择
    collegeChange(val) {
      this.queryForm.majorList = [];
      if (val.length > 0) {
        this.queryForm.collegeAcademyList.forEach((el, index) => {
          if (el === '全部') {
            delete this.queryForm.collegeAcademyList[index];
          }
        });
        let collegeList = val;
        graduateStudent.getDegreeByCollege(collegeList).then(res => {
          this.options.profession = res.data;
        });
      } else {
        this.options.profession = [];
      }
    },
    _fill(type, data) {
      for (const key in data) {
        this.options[type].push({
            value: key,
            label: data[key]
        });
      }
    },
    // // 清空新增课程
    // assessIndexDetailTable() {

    //   this.assessIndexDetailTable.internshipData = [];
    // },
    // 提交
    affirmForm() {
      // console.log(this.queryForm);
      // console.log(this.dataListProp, 'this.dataListProp');
      this.$refs['addform'].validate(valid => {
        if (valid) {
          if (this.dataProp === '新增') {
            if (this.assessIndexDetailTable.internshipData.length > 0) {
              this.$refs['assessIndexDetailTable'].validate(validst => {
                if (validst) {
                  
                  this.dataList.forEach(el => {
                    if (this.queryForm.calendarYear === el.id) {
                      this.queryForm.calendarYear = el.year;
                      this.queryForm.calendarTerm = el.term;
                      this.queryForm.calendarName = el.fullName;
                    }
                  });
                  // 学院
                  this.queryForm.collegeAcademy = this.queryForm.collegeAcademyList ? this.queryForm.collegeAcademyList.join() : '';
                  // 培养类别
                  this.queryForm.trainingType = this.queryForm.trainingCategory ? this.queryForm.trainingCategory.join() : '';
                  // 学位类型
                  // this.queryForm.degreeType = this.queryForm.degreeTypeList ? this.queryForm.degreeTypeList.join() : '';
                  // 学习形式
                  this.queryForm.learnForm = this.queryForm.learnFormList ? this.queryForm.learnFormList.join() : '';
                  // 专业
                  this.queryForm.major = this.queryForm.majorList ? this.queryForm.majorList.join() : '';
                  // 培养层次
                  this.queryForm.trainingLevel = this.queryForm.TrainingLevelList ? this.queryForm.TrainingLevelList.join() : '';
                  // if (this.queryForm.courseCode.includes('(')) {
                  //   let courseCode = this.queryForm.courseCode.split('(')[1];
                  //   this.queryForm.courseCode = courseCode.split(')')[0];
                  // }
                  this.queryForm.courseList = this.assessIndexDetailTable.internshipData;
                  let obj = Object.assign({}, this.queryForm);
                  this.innerVisible = false;
                  this.options.profession = [];
                  this.restaurants = [];
                  // console.log(obj);
                  this.$emit("affirm-form", obj); 
                }
              });
            } else {
              this.$message(this.$t('internship.pleaseCourse'));
            }
          } else if (this.dataProp === '编辑') {
            if (this.assessIndexDetailTable.internshipData.length > 0) {
              this.$refs['assessIndexDetailTable'].validate(validst => {
                if (validst) {
                  this.dataList.forEach(el => {
                    if (this.queryForm.calendarYear === el.id) {
                      this.queryForm.calendarYear = el.year;
                      this.queryForm.calendarTerm = el.term;
                      this.queryForm.calendarName = el.fullName;
                    }
                  });
                  // 培养类别
                  let training = [];
                  this.options.trainingCategory.forEach(el => {
                    if (this.queryForm.trainingCategory.length > 0) {
                      this.queryForm.trainingCategory.forEach(ele => {
                        if (el.label === ele || el.value === ele) {
                          training.push(el.value);
                        } else {
                          this.queryForm.trainingType = '';
                        }
                      });
                      this.queryForm.trainingType = training.length > 0 ? training.join() : '';
                    } else {
                      this.queryForm.trainingType = '';
                    }
                  });
                  // 学习形式
                  let learnForm = [];
                  this.options.formLearning.forEach(el => {
                    if (this.queryForm.learnFormList.length > 0) {
                      this.queryForm.learnFormList.forEach(ele => {
                        if (el.label === ele || el.value === ele) {
                          learnForm.push(el.value);
                        } else {
                          this.queryForm.learnForm = '';
                        }
                      });
                      this.queryForm.learnForm = learnForm.length > 0 ? learnForm.join() : '';
                    } else {
                      this.queryForm.learnForm = '';
                    }
                  });
                  // 学院
                  let collegeAcademy = [];
                  if (this.queryForm.collegeAcademyList.length > 0) {
                    this.options.faculty.forEach(elt => {
                      this.queryForm.collegeAcademyList.forEach(ele => {
                        if (ele === elt.label || ele === elt.value) {
                          collegeAcademy.push(elt.value);
                        } else {
                          this.queryForm.collegeAcademy = '';
                        }
                      });
                      this.queryForm.collegeAcademy = collegeAcademy.length > 0 ? collegeAcademy.join() : '';
                    });
                    // this.queryForm.collegeAcademy = this.queryForm.collegeAcademyList ? this.queryForm.collegeAcademyList.join() : '';
                  } else {
                    this.queryForm.collegeAcademy = '';
                  }
                  // 专业
                  let major = [];
                  if (this.queryForm.majorList.length > 0) {
                    this.options.profession.forEach(elt => {
                      this.queryForm.majorList.forEach(ele => {
                        if (ele === elt.name || ele === elt.code) {
                          major.push(elt.code);
                        } else {
                          this.queryForm.major = '';
                        }
                      });
                    });
                    this.queryForm.major = major.length > 0 ? major.join() : '';
                  } else {
                    this.queryForm.major = '';
                  }
                  // 培养层次
                  let trainingLevel = [];
                  this.options.TrainingLevel.forEach(el => {
                    if (this.queryForm.TrainingLevelList.length > 0) {
                      this.queryForm.TrainingLevelList.forEach(ele => {
                        if (el.label === ele || el.value === ele) {
                          trainingLevel.push(el.value);
                        } else {
                          this.queryForm.trainingLevel = '';
                        }
                      });
                      this.queryForm.trainingLevel = trainingLevel.length > 0 ? trainingLevel.join() : '';
                    } else {
                      this.queryForm.trainingLevel = '';
                    }
                  });
                  // console.log(this.queryForm, '1212');
                  // if (this.queryForm.courseCode.includes('(')) {
                  //   let courseCode = this.queryForm.courseCode.split('(')[1];
                  //   this.queryForm.courseCode = courseCode.split(')')[0];
                  // }
                  this.queryForm.degreeType = '2';
                  delete this.queryForm.majorStr;
                  delete this.queryForm.trainingLevelStr;
                  delete this.queryForm.trainingTypeStr;
                  delete this.queryForm.degreeTypeStr;
                  delete this.queryForm.learnFormStr;
                  delete this.queryForm.collegeAcademyStr;
                  let obj = Object.assign({}, this.queryForm);
                  this.options.profession = [];
                  this.restaurants = [];
                  this.$emit("affirm-form", obj); 
                  this.innerVisible = false;
                }
              });
            } else {
              this.$message(this.$t('internship.pleaseCourse'));
            }
            
          }
        }
      });
    }
    
  },
  // async
  created() {
    this.getOptions();
  }
};
</script>
